//
//  orderView.m
//  爱鲜蜂(郭少乾)
//
//  Created by GuoDeJin on 2016/11/19.
//  Copyright © 2016年 GuoDeJin. All rights reserved.
//

#import "orderView.h"
#import "Masonry.h"
//图文混排分类
#import "NSAttributedString+DJAdditon.h"
@implementation orderView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    self.backgroundColor = [UIColor whiteColor];
    
    [self addTopButton:@"v2_my_order_icon" title:@"我的订单" tag:kButtonScan];
    [self addTopButton:@"v2_my_coupon_icon" title:@"优惠券" tag:kButtonCard];
    [self addTopButton:@"v2_my_message_icon" title:@"我的消息" tag:kButtonPay];
    
}

//添加按钮的封装
- (void)addTopButton:(NSString *)imageName title:(NSString *)title tag:(HomeTopButtonType)tag{
    
    UIButton *button = [[UIButton alloc]init];
    
    //使用分类给按钮设置一个图文混排的按钮
    [button setAttributedTitle:[NSAttributedString cz_imageTextWithImage:[UIImage imageNamed:imageName] title:title fontSize:12 titleColor:[UIColor grayColor] spacing:7] forState:UIControlStateNormal];
    //设置按钮的行数为0,让按钮上的文字自动换行
    button.titleLabel.numberOfLines = 0;
    //设置按钮文字的对齐方式为居中对齐
    button.titleLabel.textAlignment = NSTextAlignmentCenter;
    //让按钮自适应大小
    [button sizeToFit];
    
    [button addTarget:self action:@selector(clickHomeTopButton:) forControlEvents:UIControlEventTouchUpInside];
    button.tag = tag;
    
    [self addSubview:button];
    
  
}


#pragma mark - 按钮点击事件  因为是view不能实现跳转,所以设置他的父类为代理  让MyVc替他push
- (void)clickHomeTopButton:(UIButton *)button{

    
        if([self.delegate respondsToSelector:@selector(pushToOtherView:)])
            
        {
            [self.delegate pushToOtherView:button];
        }

}



- (void)layoutSubviews{
    [super layoutSubviews];
    
    
    
        NSMutableArray *arr = [NSMutableArray array];
    
    for (NSInteger i = 0; i < self.subviews.count; i++) {
        
        [arr addObject:self.subviews[i]];
    }
    
        [arr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:5 leadSpacing:5 tailSpacing:5];
        [arr mas_makeConstraints:^(MASConstraintMaker *make) {
    
            make.top.bottom.equalTo(self);
            
        }];

    
}


@end
